|
|
|
|
|
|
|
Figure 13.7
At designtime, the generic data entry form
contains the beginnings of two control arrays. |
|
|
|
|
|
|
|
|
For the Data control, you will need to set the DatabaseName and RecordSource properties of the control to access a recordset. After setting up the Data control, assign the control to the DataSource property of the text box. This property will be inherited by each of the text boxes you add to the form. Next, place the code in Listing 13.2 in the form. |
|
|
|
|
|
|
|
|
Listing 13.2 GENDATA.FRMUsing the Fields Collection to Drive the Code for Creating Controls |
|
|
|
|
|
|
|
|
Option Explicit
Dim bFirstLoad As Boolean
Private Sub Form_Activate()
Dim i As Integer
Dim nFields As Integer
Dim sName As String
If Not bFirstLoad Then Exit Sub
With dtaMain.Recordset
nFields = .Fields.Count
For i = 0 To nFields - 1
sName = .Fields(i).Name
If i > 0 Then
Load lblArray(i)
Load txtArray(i)
txtArray(i).Top = txtArray(i - 1).Top + txtArray(i - 1).Height +
120
txtArray(i).Left = txtArray(i - 1).Left
lblArray(i).Top = txtArray(i).Top
lblArray(i).Left = lblArray(i - 1).Left
txtArray(i).Visible = True
lblArray(i).Visible = True
End If
lblArray(i).Caption = sName
txtArray(i).DataField = sName
Next i
End With
i = txtArray.UBound
dtaMain.Top = txtArray(i).Top + txtArray(i).Height + 120 |
|
|
|
|
|